use 	"./output/intermediate/citiesall_patents_breakthrough.dta", clear

gen npi_id = master_id if master_id<100
gen cls_id = master_id if master_id>=100

merge m:1 npi_id cls_id f_myr using "./output/cities_expandedpatents" // This merge structure privileges the master!
drop 	_merge

drop 	pat_all_inv_noassg-pat_wtd_inv_wassg 
drop 	prate_first_inv-prate_multpats_inv_wassg
drop 	pat_has_assignee
drop 	pat_first_inv pat_all_inv pat_single_inv

order 	gen_id city f_myr, first
sort 	gen_id f_myr

foreach v in wtd_inv { 
	gen prate_`v' = pat_`v'/(pop_int/100000)
}

foreach v in break_p50_rfsim05 break_p50_rfsim010 break_p50_rrfsim05 break_p50_rrfsim010 {
	gen not`v' = pat_wtd_inv - `v'
}

compress

save 	"./output/cities_expandedpatents_breakthrough.dta", replace
clear
